package Test1;

import java.util.LinkedList;
import java.util.Queue;

public class Test2 {

}
class MyStack {
    Queue<Integer> queue1;
    Queue<Integer> queue2;
    //构造
    public MyStack() {
        queue1=new LinkedList<>();
        queue2=new LinkedList<>();
    }
    //用队列实现栈
    //栈顶插入
    public void push(int x) {
        queue2.add(x);
        while (queue1.size()>0) {
            queue2.add(queue1.poll());
        }
        while (queue2.size()>0) {
            queue1.add(queue2.poll());
        }
    }


    public int pop() {
        return queue1.poll();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
    return queue1.isEmpty();
    }
}